package es.ats.codington.festival.services;

import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import es.ats.codington.festival.daos.ImageDAO;
import es.ats.codington.festival.domain.Image;
import es.ats.codington.festival.exceptions.ServiceException;
import es.ats.codington.festival.interfaces.services.IImageService;
import es.ats.codington.festival.utils.FERSDataConnection;
import es.ats.codington.festival.utils.ImageDataConnection;


public class ImageDAOService implements IImageService{

	
	private Connection conn;
	ImageDAO imageDAO = new ImageDAO();
	private Image im;
	//ImageDataConnection idc;
	boolean compro;
	static String ruta = "C:\\Users\\JAVA101_01\\Desktop\\park2.jpg";
	static String nombre = "img_park";
	
	public ImageDAOService() {
		super();

		im=new Image();
			
	}
	
	/**
	 *  SETTER methods for ImageDAOService class 
	 * @return
	 */
	public boolean guardarImagenService(String ruta,String nombre){
		
		try{
			conn = ImageDataConnection.getConnection();
			compro = imageDAO.guardarImagen(ruta,nombre,conn);
			conn.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return compro;
	}
	
	
	/**
	 * methods for ImageDAOService class
	 * @return
	 */
	public List<Image> getImagenesServices() {
		
		List<Image> lista = new ArrayList<Image>();
		try{
			conn = ImageDataConnection.getConnection();
			lista = imageDAO.getImagenes(conn);
			conn.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return lista;
	}
	
	/**
	 *  GETTER methods for ImageDAOService class 
	 * @return
	 */
	public Image getImageByIdService(int idImage){
		try{
			conn = ImageDataConnection.getConnection();
			im = imageDAO.getImageById(idImage, conn);
			conn.close();
		}catch (SQLException e){
			System.out.println(e.getMessage());
		}
		return im;
		
	}
	
	
	
	
	
	/*public Image checkImageById(int idImage){

        try{
            conn = ImageDataConnection.getConnection();
            Image img = ImageDAO.getImageById(idImage, conn);
            conn.close();
            return img;
        }
        catch (SQLException e) {
        	System.out.println(e.getMessage());
        }
	}*/

}
